
package com.sfeir.gwt.webding.client.component;

import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * Classe permettant de faire une ossature d'une application avec :
 * - un bandeau au dessus, 
 * - un menu à droite (ou à gauche), 
 * - et des onglets au centre
 * @author sfeir
 */
public class Ossature extends Composite {
    public static final Boolean DIRECTION_LEFT = true;
    
    public static final Boolean DIRECTION_RIGHT = false;
    
    // Layout principale (Bandeau, Centre, et barre de statut)
    private VerticalPanel panel;
    
    // Bandeau du haut de l'application
    private AbsolutePanel header;
    
    // Centre de l'application (menu de gauche et onglets centraux)
    private HorizontalPanel center;
    
    // Conteneur du menu de gauche
    private CollapsePanel menu;
    
    // Onglet centraux
    private ClosableTabPanel body;
    
    // Barre de statut
    private Label status;
    
    public Ossature() {
        createLayout(DIRECTION_LEFT);
    }
    
    /**
     * 
     * @param menuDirection Definie la position du menu (true a gauche sinon a droite)
     */
    public Ossature(Boolean menuDirection) {
        createLayout(menuDirection);
    }
    
    /**
     * Initialize tous le layout
     * @param menuDirection Definie la position du menu (true a gauche sinon a droite)
     */
    private void createLayout(Boolean menuDirection) {
        panel = new VerticalPanel();
        panel.addStyleName("ossature-root-panel");
        panel.setSize("100%", "96%");
        
        header = new AbsolutePanel();
        header.addStyleName("ossature-header-panel");
        header.setSize("100%", "82px");
        
        menu = new CollapsePanel("", true, menuDirection);
        menu.addStyleName("ossature-menu-panel");
        menu.setSize("100%", "100%");
        
        body = new ClosableTabPanel();
        body.setAnimationEnabled(true);
        body.addStyleName("ossature-body-panel");
        body.setSize("100%", "100%");
        body.getDeckPanel().setSize("100%", "100%");
        
        // center = new HorizontalSplitPanel();
        center = new HorizontalPanel();
        center.addStyleName("ossature-center-panel");
        center.setSize("100%", "96%");
        // center.setSplitPosition("175px");
        if (menuDirection) {
            center.add(menu);
            center.add(body);
        }
        else {
            center.add(body);
            center.add(menu);
        }
        center.setCellWidth(body, "100%");
        
        status = new Label();
        status.addStyleName("ossature-status-panel");
        status.setSize("100%", "10px");
        
        panel.add(header);
        panel.setCellHeight(header, "60px");
        panel.add(center);
        panel.setCellHeight(center, "100%");
        panel.add(status);
        panel.setCellHeight(status, "15px");
        
        initWidget(panel);
    }
    
    public Widget getMenu() {
        return menu.getContent();
    }
    
    public void setMenu(Widget menu_widget) {
        menu.add(menu_widget);
    }
    
    public AbsolutePanel getHeader() {
        return header;
    }
    
    /**
     * @return
     */
    public ClosableTabPanel getBody() {
        return body;
    }
    
    /**
     * Affiche un message dans le status
     * 
     * @param text
     */
    public void setStatus(String text) {
        status.setText(text);
    }
}
